package com.clp.protocol.iec104.client.pipeline.codec;

import com.clp.protocol.iec104.apdu.Apdu;
import com.clp.protocol.iec104.apdu.ApduFactory;
import com.clp.protocol.iec104.client.Master;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 不需释放 bytebuf
 */
@Slf4j
public class BytesToApduDecoder extends ByteToMessageDecoder {
    private final Master master;

    public BytesToApduDecoder(Master master) {
        this.master = master;
    }

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        Apdu apdu = ApduFactory.getApdu(byteBuf);
        list.add(apdu);
    }
}
